package com.water.controller;

import com.water.entity.SyEmp;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("yonghu")
public class ForwardController {

    @RequestMapping("/index")
    public String index(Model model){   // 测试freemarker
        //跳转到 index.ftl
        //共享域
        model.addAttribute("name", "");

        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add("小花"+i);
        }

        model.addAttribute("list",list);//将集合放进共享域，list必须与ftl模板中的key保持一致
        return "index";
    }

    /**
     * 跳转到主页面
     * @return
     */
    @RequestMapping("/workspace")
    public String workspace(Model model, HttpSession httpSession, SyEmp syemp){
        syemp= (SyEmp) httpSession.getAttribute("user");
        model.addAttribute("name",syemp.getEmpname());
        return "workspace";
    }


    /**
     *跳转到用户申请
     * @return
     */
    @RequestMapping("/request")
    public String request(HttpSession httpSession, HttpServletRequest httpServletRequest){
        httpSession=httpServletRequest.getSession();
        String ordno = "0000";//防报错
        httpSession.setAttribute("ordno",ordno);
        return "be/be__request";
    }
    /**
     * 跳转到新户
     * @return
     */
    @RequestMapping("/request1")
    public String request1(){
        return "be/be__request1";
    }
    /**
     * 跳转到过户
     * @return
     */
    @RequestMapping("/request2")
    public String request2(){
        return "be/be__request2";
    }
    /**
     * 跳转到分户
     * @return
     */
    @RequestMapping("/request3")
    public String request3(){
        return "be/be__request3";
    }
    /**
     * 跳转到代扣
     * @return
     */
    @RequestMapping("/request4")
    public String request4(){
        return "be/be__request4";
    }
    /**
     * 跳转到换表
     * @return
     */
    @RequestMapping("/request5")
    public String request5(){
        return "be/be__request5";
    }
    /**
     * 跳转到重签
     * @return
     */
    @RequestMapping("/request6")
    public String request6(){
        return "be/be__request6";
    }
    /**
     * 跳转到销户
     * @return
     */
    @RequestMapping("/request7")
    public String request7(){
        return "be/be__request7";
    }
    /**
     * 跳转到工单
     * @return
     */
    @RequestMapping("/requestOrder")
    public String requestOrder(){
        return "be/be__requestOrder";
    }
    @RequestMapping("/suces")
    public String success(@RequestParam("pagename") String pagename){
        String page="";
        if (pagename.equals("request1")) {
            page="success";
        }
        if (pagename.equals("request2")) {
            page="success";
        }
        if (pagename.equals("request3")) {
            page="success";
        }
        if (pagename.equals("request4")) {
            page="success";
        }
        if (pagename.equals("request5")) {
            page="success";
        }
        if (pagename.equals("request6")) {
            page="success";
        }
        if (pagename.equals("request7")) {
            page="success";
        }
        if (pagename.equals("requestOrder")) {
            page="success";
        }
        if (pagename.equals("abort")) {
            page="success";
        }
        return page;
    }
    @RequestMapping("error")
    public String error(){
        String pagename="error";
        return pagename;
    }

}
